package demo4;

import java.util.Arrays;
import java.util.Comparator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 何华树
 * Date: 2024-09-06
 * Time: 9:47
 */
public class Test1 {
    public static void mySort(Comparable[] comparables) {
        for (int i = 0;i<comparables.length-1;i++) {
            for (int j = 0; j < comparables.length-1-i; j++) {

                if(comparables[j].compareTo(comparables[j+1]) > 0) {

                    Comparable tmp = comparables[j];
                    comparables[j] = comparables[j+1];
                    comparables[j+1] = tmp;
                }
            }
        }
    }
    public static void main2(String[] args) {
        Person[] persons = new Person[3];
        persons[0] = new Person("zhangsan",10);
        persons[1] = new Person("lisi",12);
        persons[2] = new Person("abc",19);
        System.out.println("排序之前："+Arrays.toString(persons));
//        mySort(persons);
        NameComparator nameComparator = new NameComparator();
        AgeComparator ageComparator = new AgeComparator();
        Arrays.sort(persons,ageComparator);
        System.out.println("排序之后："+Arrays.toString(persons));
    }
    public static void main1(String[] args) {
        Person p1 = new Person("zhangsan",10);
        Person p2 = new Person("lisi",12);
        System.out.println(p1.compareTo(p2));
    }
}
